package my.jwds.p205;

import java.util.HashMap;
import java.util.Map;

public class IsIsomorphic {

    public static void main(String[] args) {
        IsIsomorphic obj = new IsIsomorphic();
        System.out.println(obj.isIsomorphic("foo","bar"));
    }

    public boolean isIsomorphic(String s, String t) {
        Map<Character,Character> sMap = new HashMap<>();
        Map<Character,Character> tMap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char chars = s.charAt(i);
            char chart = t.charAt(i);
            Character tchar = sMap.get(chars);
            Character schar = tMap.get(chart);
            if (tchar == null && schar == null){
                sMap.put(chars,chart);
                tMap.put(chart,chars);
            }else if (schar!=null && chars != schar || tchar!=null && chart != tchar){
                return false;
            }
        }
        return true;
    }
}